package it.abc.sicsic.view.backing.clienti;

import it.abc.sicsic.JavaServiceFacade;
import it.abc.sicsic.model.clienti.Clienti;
import it.abc.sicsic.view.backing.NauticaTemplate;
import it.abc.sicsic.view.util.ViewUtil;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;

import oracle.adf.view.rich.component.rich.RichDocument;
import oracle.adf.view.rich.component.rich.RichForm;
import oracle.adf.view.rich.component.rich.input.RichInputText;

//import org.apache.log4j.Logger;

@ManagedBean(name = "backing_dettaglioClienti")
@SessionScoped

public class DettaglioClienti {
    private RichInputText itNome;
    private RichInputText itCognome;
    private RichInputText itRagSociale;
    private RichInputText itNatoIl;
    private RichInputText itNatoA;
    private RichInputText itIndirizzo;
    private RichInputText itSedeLegale;
    private RichInputText itCitta;
    private RichInputText itProvincia;
    private RichInputText itDocumento;
    private RichInputText itTelefono;
    private RichInputText itFax;
    private RichInputText itEmail;
    //private static Logger logger = Logger.getLogger(DettaglioClienti.class);
    
    public DettaglioClienti(){
      //  logger.info("DettaglioClienti start");
      //  logger.info("fromPage=" + ViewUtil.getRequestFromPage());      
    }
    
    public void salva(ActionEvent actionEvent) {
        JavaServiceFacade serviceFacede = new JavaServiceFacade();
        Clienti cliente = buildCliente();
        serviceFacede.persistClienti(cliente);
    }

    public void setItNome(RichInputText nome) {
        this.itNome = nome;
    }

    public RichInputText getItNome() {
        return itNome;
    }

    public void setItCognome(RichInputText cognome) {
        this.itCognome = cognome;
    }

    public RichInputText getItCognome() {
        return itCognome;
    }

    public void setItRagSociale(RichInputText ragSociale) {
        this.itRagSociale = ragSociale;
    }

    public RichInputText getItRagSociale() {
        return itRagSociale;
    }

    public void setItNatoIl(RichInputText natoIl) {
        this.itNatoIl = natoIl;
    }

    public RichInputText getItNatoIl() {
        return itNatoIl;
    }

    public void setItNatoA(RichInputText natoA) {
        this.itNatoA = natoA;
    }

    public RichInputText getItNatoA() {
        return itNatoA;
    }

    public void setItIndirizzo(RichInputText indirizzo) {
        this.itIndirizzo = indirizzo;
    }

    public RichInputText getItIndirizzo() {
        return itIndirizzo;
    }

    public void setItSedeLegale(RichInputText sedeLegale) {
        this.itSedeLegale = sedeLegale;
    }

    public RichInputText getItSedeLegale() {
        return itSedeLegale;
    }

    public void setItCitta(RichInputText citta) {
        this.itCitta = citta;
    }

    public RichInputText getItCitta() {
        return itCitta;
    }

    public void setItProvincia(RichInputText provincia) {
        this.itProvincia = provincia;
    }

    public RichInputText getItProvincia() {
        return itProvincia;
    }

    public void setItDocumento(RichInputText documento) {
        this.itDocumento = documento;
    }

    public RichInputText getItDocumento() {
        return itDocumento;
    }

    public void setItTelefono(RichInputText telefono) {
        this.itTelefono = telefono;
    }

    public RichInputText getItTelefono() {
        return itTelefono;
    }

    public void setItFax(RichInputText fax) {
        this.itFax = fax;
    }

    public RichInputText getItFax() {
        return itFax;
    }

    public void setItEmail(RichInputText email) {
        this.itEmail = email;
    }

    public RichInputText getItEmail() {
        return itEmail;
    }
    
    private String getNome(){
        return ViewUtil.getStringValue(getItNome());   
    }
    private String getCognome(){
        return ViewUtil.getStringValue(getItCognome());   
    }
    private String getRagSociale(){
        return ViewUtil.getStringValue(getItRagSociale());   
    }
    private String getNatoIl(){
        return ViewUtil.getStringValue(getItNatoIl());
    }
    private String getNatoA(){
        return ViewUtil.getStringValue(getItNatoA());
    }
    private String getIndirizzo(){
        return ViewUtil.getStringValue(getItIndirizzo());
    }
    private String getSedeLegale(){
        return ViewUtil.getStringValue(getItSedeLegale());
    }
    private String getCitta(){
        return ViewUtil.getStringValue(getItCitta());
    }
    private String getProvincia(){
        return ViewUtil.getStringValue(getItProvincia());
    } 
    private String getDocumento(){
        return ViewUtil.getStringValue(getItDocumento());
    }
    private String getTelefono(){
        return ViewUtil.getStringValue(getItTelefono());
    }
    private String getFax(){
        return ViewUtil.getStringValue(getItFax());
    }
    private String getEmai(){
        return ViewUtil.getStringValue(getItEmail());
    }
    /** SETTA VALORI DEL CLIENTE */
    private Clienti buildCliente(){
        Clienti cliente = new Clienti();
        cliente.setNome(getNome());
        cliente.setCognome(getCognome());
        cliente.setNatoIl(getNatoIl());
        cliente.setNatoA(getNatoA());
        cliente.setRagioneSociale(getRagSociale());
        cliente.setIndirizzo(getIndirizzo());
        cliente.setSedeLegale(getSedeLegale());
        cliente.setProvincia(getProvincia());
        cliente.setCitta(getCitta());
        cliente.setDocumento(getDocumento());
        cliente.setTelefono(getTelefono());
        cliente.setFax(getFax());
        cliente.setEmail(getEmai());
        return cliente;
    }
}
